<template>
	<view>
		<view class="Search">
			<u-search @change="Search" v-model="keyword" bg-color="#202126" placeholder="输入你想要搜索的商品" shape="square"
				:show-action="false"></u-search>
		</view>
		<view class="GoodsList">
			<view class="GoodsItem" v-for="(Item, Index) in GoodList" :key="Index"
				@click="GoDetail(Item.goods_id,Item.id)">
				<view class="ItemLeft">
					<image :src="Item.image" style="width: 252rpx;height: 252rpx;border-radius: 20rpx;" mode=""></image>
				</view>
				<view class="ItemRight">
					<view class="Name">{{ Item.goods_name }}</view>
					<!-- <view class="DelPrice_BuyNum">
						<view class="DelPrice">￥{{ Item.goods_price }}</view>
						<view class="BuyNum">已售{{ Item.goods_buy_count }}件</view>
					</view> -->
					<view class="BuyPrice">
						<text>{{ Item.point }}</text>积分+<text>{{ Item.jinbi }}</text>
						抵用券
					</view>
				</view>
			</view>
			<view v-if="showEnd && GoodList.length > 0" class="endLine">
				-&nbsp;&nbsp;我是有底线的&nbsp;&nbsp;-
			</view>
			<view v-if="GoodList.length === 0" class="noData">
				暂无数据，请检查您的搜索条件！
			</view>
		</view>
		<jh-tabbar></jh-tabbar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page: 1,
				pageSize: 20,
				keyword: "",
				GoodList: [],
				isLoading: false,
				showEnd: false,
				timer: null,
			};
		},
		onLoad() {
			this.GetList();
		},
		methods: {
			//搜索
			Search() {
				if (this.timer) { // 如果已经设置了定时器，就清除已有的定时器
					clearTimeout(this.timer);
				}
				this.timer = setTimeout(() => {
					this.page = 1;
					this.showEnd = false;
					this.GetList();
				}, 1000); // 设置新的定时器，500ms 后执行搜索
			},
			//获取数据
			GetList() {
				if (this.isLoading || this.showEnd) {
					return;
				}
				this.isLoading = true;
				this.$api.SpecialList({
						page: this.page,
						limit: this.pageSize,
						keyword: this.keyword,
					},
					(res) => {
						let data = res.data;
						if (data.length > 0) {
							if (this.page === 1) {
								this.GoodList = data;
							} else {
								this.GoodList = this.GoodList.concat(data);
							}
							this.page++;
							this.isLoading = false;
						} else {
							if (this.page === 1) {
								this.GoodList = [];
							}
							this.showEnd = true;
							this.isLoading = false;
						}
					}
				);
			},
			//跳转
			GoDetail(ID, PointID) {
				uni.navigateTo({
					url: '/pages/Special/SpecialDetail?id=' + ID + '&pid=' + PointID
				})
			}
		},
		onReachBottom() {
			this.GetList();
		},
	};
</script>

<style lang="scss" scoped>
	.Search {
		margin: 104rpx 30rpx 20rpx;
	}

	.GoodsList {
		margin: 0 30rpx;

		.GoodsItem {
			display: flex;
			background: #202126;
			padding: 15rpx;
			margin-bottom: 30rpx;
			border-radius: 20rpx;

			.ItemLeft {
				margin-right: 26rpx;
			}

			.ItemRight {
				padding-top: 15rpx;

				.Name {
					height: 90rpx;
					color: #FFFFFF;
					font-weight: 800;
					display: -webkit-box;
					overflow: hidden;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

				.DelPrice_BuyNum {
					display: flex;
					justify-content: space-between;
					font-size: 24rpx;
					color: #B9B9B9;
					margin: 25rpx 0 20rpx;

					.DelPrice {
						text-decoration: line-through;
					}

					.BuyNum {}
				}

				.BuyPrice {
					font-size: 28rpx;
					color: #F2D7AA;

					text {
						font-weight: bold;
						font-size: 36rpx;
					}
				}
			}
		}
	}

	.endLine {
		text-align: center;
		margin-bottom: 20rpx;
		color: #999;
	}

	.noData {
		text-align: center;
		margin-top: 100rpx;
		color: #999;
	}
</style>